import time

from django.db import models


class Book(models.Model):
    title = models.CharField(max_length=200, verbose_name="书名")
    price = models.FloatField(verbose_name="价格")
    publish_date = models.DateTimeField(auto_now_add=True, null=True)
    # 书 出版社 一对多
    publish = models.ForeignKey(to="Publish", on_delete=models.CASCADE)
    # 书作者 多对多
    authors = models.ManyToManyField(to="Author")


class Author(models.Model):
    gender_choice = [
        ('1', "男"),
        ('2', "女")
    ]
    name = models.CharField(max_length=200, verbose_name="作者姓名")
    gender = models.CharField(max_length=200, verbose_name="性别", choices=gender_choice)
    # 作者 作者详情 一对一
    author_detail = models.OneToOneField(to="AuthorDetail", on_delete=models.CASCADE)


class AuthorDetail(models.Model):
    age = models.IntegerField(verbose_name="作者年龄")
    phone = models.CharField(max_length=100, verbose_name="作者电话")
    address = models.CharField(max_length=200, verbose_name="作者地址")


class Publish(models.Model):
    name = models.CharField(max_length=200, verbose_name="出版社名称")
    addr = models.CharField(max_length=200, verbose_name="出版社地址")
